package ns2;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

/**
 * Main class of application
 * @author Thimor Bohn <bohn@itm.uni-luebeck.de>
 *
 */
public class Main {

	/**
	 * Entry point of application
	 * @param args
	 */
	public static void main(String[] args) 
	{
		// parse parameters
		String net = "C:\\dev\\latexsrc\\trunk\\Traffic Paper\\simu\\single\\single.net.xml";
		String trace="C:\\dev\\latexsrc\\trunk\\Traffic Paper\\simu\\single\\netstate.xml";
		String output = "C:\\a.txt";
		String rn = "C:\\rn.txt";
		
		for (int i=0; i<args.length; i++) {
			
			if ("-n".equals(args[i])) {
				// net file
				if (++i<args.length) {
					if (!args[i].startsWith("-")) {
						net = args[i];
					}
				}
			}
					
			if ("-t".equals(args[i])) {
				// trace file
				if (++i<args.length) {
					if (!args[i].startsWith("-")) {
						trace = args[i];
					}
				}
			}
			
			if ("-o".equals(args[i])) {
				// output file
				if (++i<args.length) {
					if (!args[i].startsWith("-")) {
						output = args[i];
					}
				}
			}
			
			if ("-or".equals(args[i])) {
				// road network file
				if (++i<args.length) {
					if (!args[i].startsWith("-")) {
						rn = args[i];
					}
				}
			}
			
		}

		Main.convert(net, trace, output, rn);
		
		System.out.println("DONE!");
	}
    
	
	public static void convert(String net, String trace, String output, String rn) 
	{
		// 1. get net
		List<Edge> edges = new LinkedList<Edge>();
		Map<String, Junction> junctions = new HashMap<String, Junction>();
		NetReader.read(net, edges, junctions);
		
		// 2. translate net to avoid negative value
		// NetTranslater.translate(edges, junctions);
		
		// 3. get all vehicles movement info
		Map<String, Vector<NSMobilityItem>> vInfo = new HashMap<String, Vector<NSMobilityItem>>();
		VehicleReader.read(trace, vInfo, edges);
		
		// 4. write to file
		try {
			MobilityWriter.write(vInfo, output);
		} catch (Exception e) {
			e.printStackTrace();
		}
		

	}
		
		
}
